﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;

namespace PCRemoteMobileVer
{
    public partial class FunctionsPage : PhoneApplicationPage
    {
        public FunctionsPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DnsEndPoint ipAddress = MainPage.client.GetSocket().RemoteEndPoint as DnsEndPoint;
            FunctionsPanorama.Title = ipAddress.Host.ToString();
        }

        private void btShutdown_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("Shutdown");
        }

        private void btRestart_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("Restart");
        }

        private void btSleep_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("Sleep");
        }

        private void btHibernate_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("Hibernate");
        }

        private void btTakeSnap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //MessageBox.Show("Take Screenshot " + MainPage.SendCommand("TakeSnap"));
            //byte[] imageData = MainPage.client.ReceiveImage();
            //if (imageData == null)
            //{
            //    MessageBox.Show("WARNING: Get Screen Error!");
            //    return;
            //}

            //MessageBox.Show("Received image data :" + System.Text.Encoding.UTF8.GetString(imageData, 0, imageData.Length));
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }

        private void btPowerpoint_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_POWERPOINT");
            NavigationService.Navigate(new Uri("/Functions/PowerPointPage.xaml", UriKind.Relative));
        }

        private void btWindowsMediaPlayer_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_WINDOWSMEDIAPLAYER");
            NavigationService.Navigate(new Uri("/Functions/MediaPlayerPage.xaml", UriKind.Relative));
        }

        private void btKeyboard_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/KeyboardSimulator.xaml", UriKind.Relative));
        }

        private void btLogOff_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("LogOff");
        }

        private void btLock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("LockSession");
        }

        private void mouseSimulator_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }

        private void btBrowser_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_BROWSER");
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }

        private void btOpenWord_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_WORD");
            NavigationService.Navigate(new Uri("/KeyboardSimulator.xaml", UriKind.Relative));
        }

        private void btExplorer_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_EXPLORER");
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }

        private void btOpenRunDialog_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MainPage.SendCommand("OPEN_NOTEPAD");
            NavigationService.Navigate(new Uri("/KeyboardSimulator.xaml", UriKind.Relative));
        }

        private void btVolumne_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/VolumeAdjust.xaml", UriKind.Relative));
        }

    }
}